<template>
  <el-date-picker class="datepicker" :size="size"  @change="gettime" v-model="time"  :type="type" align="right" unlink-panels
    range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions" :value-format="format">
  </el-date-picker>
</template>

<script>
  export default {
    data() {
      return {
          pickerOptions: {
           shortcuts: [{
             text: '最近一周',
             onClick(picker) {
               const end = new Date();
               const start = new Date();
               start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
               picker.$emit('pick', [start, end]);
             }
           }, {
             text: '最近一个月',
             onClick(picker) {
               const end = new Date();
               const start = new Date();
               start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
               picker.$emit('pick', [start, end]);
             }
           }, {
             text: '最近三个月',
             onClick(picker) {
               const end = new Date();
               const start = new Date();
               start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
               picker.$emit('pick', [start, end]);
             }
           },
           ]
         },
        time:this.default,
      };
    },
    props:{
      size: {
        type: String,
        default: ''
      },
      default:{
        type:Array,
        default:function(){
          return [];
        }
      },
      type:{
        type:String,
        default:'daterange'
      },
      format:{
        type:String,
        default:'yyyy-MM-dd'
      }
    },

    methods: {
      gettime(value) {
        this.$emit('change',value)
      }
    }
  };
</script>

<style>
  .datepicker{
    background: #FBFDFF;
    border: 1px solid #999999;
    box-shadow: 0px 2px 7px 0px rgba(0, 0, 0, 0.04);
    border-radius: 7px;
  }
</style>
